package com.fi.common.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * swagger2 配置
 */
@Configuration
@EnableSwagger2WebMvc
@EnableKnife4j
public class Swagger2Config {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("default")
                .useDefaultResponseMessages(false) // 表示不使用默认错误消息
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .apis(RequestHandlerSelectors.basePackage("com.fi.fund.controller"))
                .paths(PathSelectors.any())
                .paths(PathSelectors.regex("/error.*").negate()) // 排除 basic-error-controller
                .paths(PathSelectors.regex("/easypoi.*").negate()) // 排除 easypoi-web
                .build();// 支持的通讯协议集合
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // 标题
                .title("公募基金后台服务API接口文档")
                // 简介
                .description("适用于后台管理")
                // 更新服务条款url
                .termsOfServiceUrl("https://i60.banklaw.com/")
                // 作者
                .contact(new Contact("ljh", "https://i60.banklaw.com/", "ljhcyx@qq.com"))
                // 版本
                .version("1.0.0")
                // 构建
                .build();
    }
}